package com.headmaster.wap.system;

import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.alibaba.druid.util.StringUtils;

public class SpringPropertyExt extends PropertyPlaceholderConfigurer {

	@Override 
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) 
                    throws BeansException { 
		    //这里说明一下Url 里面的分隔符“&amp;”必须手动过滤掉，否则spring使用会无法转义，导致数据库乱码
		    String url = props.getProperty("jdbc_url");
		   
		    int x = url.indexOf("&amp;");
		    if(x!=-1){
		    	url = url.replace("&amp;", "&");
		    }
		    
            if (url != null) { 
                //解密jdbc.password属性值，并重新设置 
                props.setProperty("jdbc_url",url); 
            } 
 
            String userName = props.getProperty("jdbc_username");
            if(!StringUtils.isEmpty(userName)){
            	props.setProperty("jdbc_username", CryptionUtil.decrypt(userName));
            }
            
            String password = props.getProperty("jdbc_password");
            if(!StringUtils.isEmpty(password)){
            	props.setProperty("jdbc_password", CryptionUtil.decrypt(password));
            }
            super.processProperties(beanFactory, props); 
    } 
}
